#import "CarLrpPlugin.h"
//#if __has_include(<car_lrp_plugin/car_lrp_plugin-Swift.h>)
//#import <car_lrp_plugin/car_lrp_plugin-Swift.h>
//#else
// Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
//#import "car_lrp_plugin-Swift.h"
//#endif
#import "CameraViewController.h"

@implementation CarLrpPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
//  [SwiftCarLrpPlugin registerWithRegistrar:registrar];
    
    FlutterMethodChannel* channel = [FlutterMethodChannel
                                     methodChannelWithName:@"car_lrp_plugin"
                                     binaryMessenger:[registrar messenger]];
    CarLrpPlugin* instance = [[CarLrpPlugin alloc] init];
    [registrar addMethodCallDelegate:instance channel:channel];
}


- (void)dealloc
{
    NSLog(@"我走了啊啊啊啊啊啊啊啊啊");
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result
{
    if ([@"getPlatformVersion" isEqualToString:call.method])
    {
        result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
    }
    else if ([@"openScan" isEqualToString:call.method])
    {
        /**
         *
         *
         */
        CameraViewController* video = [CameraViewController new];
        video.resultCB = ^(NSString* text, UIImage* image) {
//            self.imageView.image = image;
//            self.resultLabel.text = text;
            if (!text && !image) {
//                NSData *imageData = UIImagePNGRepresentation(image);
//                const uint8_t *uint = (uint8_t*)[imageData bytes];
                result(@{@"code":@"123",@"frame":image});
            }
        };
//        let vc = UIApplication.shared.delegate!.window!!.rootViewController!;
        UIViewController *vc = [[UIApplication sharedApplication] delegate].window.rootViewController;
//        vc.showDetailViewController(camera, sender: nil);
        [vc showDetailViewController:video sender:nil];

//        [self presentViewController:video animated:YES completion:nil];
        
    }
    
}
@end
